package cn.com.huzo.repository.inventory.impl;

import cn.com.huzo.model.entities.inventory.StockOutLinesEntity;
import cn.com.huzo.repository.inventory.StockOutLinesRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 领料出库明细数据访问对象。
 *
 * @author 吴旭
 */
@Repository("StockOutLinesRepository")
public class StockOutLinesRepositoryImpl extends GenericRepositoryImpl<StockOutLinesEntity, String>
        implements StockOutLinesRepository {

    private final String namespace = "cn.com.huzo.repository.inventory.StockOutLinesRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public StockOutLinesRepositoryImpl() {
        super(StockOutLinesEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<StockOutLinesEntity> fetchByHeaderId(Long headerId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderId"), headerId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(Long headerId, Long rsHeaderId, Long userId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("RsHeaderId", rsHeaderId);
        criterion.put("CreatedBy", userId);
        criterion.put("UpdatedBy", userId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(namespace,
                "insert"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer supplement(Long headerId, Long rsHeaderId, Long userId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("RsHeaderId", rsHeaderId);
        criterion.put("CreatedBy", userId);
        criterion.put("UpdatedBy", userId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(namespace,
                "supplement"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<StockOutLinesEntity> itemList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchDelete(List<StockOutLinesEntity> itemList) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchDelete"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer delete(String key) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "delete"), key);
    }
}
